﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BasePlatformNet;
using BasePlatformCommon;

namespace L9SubSet {
    public partial class Form_ChipChannel : Form {
        public Form_ChipChannel(Form_MainSet main, BaseCoreNet netCore, int max, int curr) {
            InitializeComponent();
            this.StartPosition = FormStartPosition.CenterParent;
            this.netCore = netCore;
            this.parent = main;
            this.maxVal = max;
            this.currVal = curr;

            trackBarR.Maximum = max;

            trackBarR.Value = curr;

            trackBarR_Scroll(null, null);

            setLanguageText();
        }

        private BaseCoreNet netCore;
        private Form_MainSet parent;
        private int maxVal = 255;
        private int currVal = 255;

        private string section = "ChipChannel";

        private void trackBarR_Scroll(object sender, EventArgs e) {
            tbR.Text = trackBarR.Value.ToString();
        }

        private void tbR_TextChanged(object sender, EventArgs e) {
            var val = maxVal;
            if (int.TryParse(tbR.Text, out val)) {
                trackBarR.Value = val;
            }
        }

        private void btnApply_Click(object sender, EventArgs e) {
            var data = getData();
            if (data == null) {
                return;
            }
            parent.SetSelfChanVal(data);
            parent.DmxSaveButtonClick();
        }

        private byte[] getData() {
            var data = new byte[32];
            data[0] = (byte)(trackBarR.Value);
            return data;
        }

        private void setLanguageText() {
            if (!LanguageOper.available) {
                return;
            }
            this.Text = LanguageOper.ReadValue(section, "ChipChannel.Text");
            btnApply.Text = LanguageOper.ReadValue(section, "btnApply.Text");
            label1.Text = LanguageOper.ReadValue(section, "label1.Text");
        }
    }
}
